home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Macintosh Sample Code / SC.012.Signals / TestCignal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-31  |  2.4 KB  |  106 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Exception handling for MPW Pascal, MacApp and MPW C
  6. #
  7. #    UFailure (aka Signals) - “Exceptional code, with a few exceptions.”
  8. #
  9. #    TestCignal.c    -    Test tool for c access to enhanced UFailure
  10. #
  11. #    Copyright © 1985-1988 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    1.0                    11/88
  15. #
  16. #    Components:    UFailure.p            November 1, 1988
  17. #                UFailure.h            November 1, 1988
  18. #                UFailure.inc1.p        November 1, 1988
  19. #                UFailure.a            November 1, 1988
  20. #                TestCignal.c        November 1, 1988
  21. #                TestCignal.make        November 1, 1988
  22. #                TestSignal.p        November 1, 1988
  23. #                TestSignal.make        November 1, 1988
  24. #
  25. #    UFailure (or Signals) is a set of exception handling routines suitable for
  26. #    use with MacApp, MPW C, and MPW Pascal. It is a jazzed-up version of the MacApp
  27. #    UFailure unit. There is a set of C interfaces to it as well.
  28. #
  29. ------------------------------------------------------------------------------*/
  30.  
  31. #include    <Types.h>
  32. #include    <stdio.h>
  33. #include    <Errors.h>
  34. #include    <UFailure.h>            /* c interfaces to UFailure stuff */
  35.  
  36.  
  37. FailInfo    fi;
  38.  
  39.  
  40. pascal void Handler(short code, long message)
  41. {
  42.     fprintf(stdout, "Handler() from Never(); message= %d, code= %d\n", message, code);
  43.     /* this will do an implicit Failure() when it exits */
  44. }
  45.  
  46.  
  47. void Never()
  48. {
  49.     short        code;
  50.     
  51.     CatchCFailures(&fi, Handler);    /* any caught by this one go to Handler */
  52.  
  53.     if (code = CatchSignal()) {        /* if we’re getting a signal then… */
  54.         fprintf(stdout, "Never() shouldn’t get here; code= %d\n", code);
  55.         return;
  56.     }
  57.     
  58.     FreeSignal();                    /* “pop” the last Catchxxx */
  59.     
  60.     SignalMessage(7, 77777);
  61. }
  62.  
  63.  
  64. void Failer()
  65. {
  66.     if (!CatchSignal())
  67.         Never();                    /* call Never; if a signal comes, fall through */
  68.  
  69.     Failure(69, 0);                    /* fail no matter what */
  70. }
  71.  
  72.  
  73. long Value()
  74. {
  75.     short        code;
  76.     
  77.     if (code = CatchSignal()) {
  78.         fprintf(stdout, "Shouldn’t be here in Value(); code= %d\n", code);
  79.         return code;
  80.     }
  81.  
  82.     /* when this does its return the CatchSignal above will be automatically popped */
  83.     if (code = CatchSignal())
  84.         return code;
  85.     
  86.     Failer();
  87. }
  88.  
  89.  
  90. main()
  91. {
  92.     short                code;
  93.     volatile long        registerLong = 0;
  94.     
  95.     InitUFailure();
  96.  
  97.     if (code = CatchSignal()) {
  98.         fprintf(stdout, "Signal caught in main(); code = %d, registerLong = %d\n",
  99.             code, registerLong);
  100.         return 0;
  101.     }
  102.     
  103.     registerLong = 0xffff;
  104.     
  105.     Signal(Value());
  106. }